import {
    createRouter,
    createWebHashHistory,
    RouteRecordRaw
} from 'vue-router'
import {useUserStore} from "../store/user";
import { useTitle } from '@vueuse/core'
let routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/home'
    },
  
   
     {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/home.vue'),
        meta: {
            title: 'home'
        }
    },
    {
        path: '/home/add',
        name: 'add',
        component: () => import('@/views/home/add.vue'),
        meta: {
            title: '创建订单'
        }
    },
    {
        path: '/home/list',
        name: 'list',
        component: () => import('@/views/home/list.vue'),
        meta: {
            title: '订单列表'
        }
    },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})
router.beforeEach((async (to, from, next) => {
    const title = useTitle()
    title.value = to.meta.title as string 
    console.log(to.query);
    if (to.query.user_token) {
        localStorage.setItem('user_token', to.query.user_token as string)
    }
    next()
}))


router.afterEach(() => {
  
})



export default router


